package cn.tlb.retrofit;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.x;

import cn.tlb.Constants;
import cn.tlb.retrofit.local_get.LocalService;
import cn.tlb.retrofit.local_get.User;
import cn.tlb.xutilsdownload.R;
import retrofit.Call;
import retrofit.Callback;
import retrofit.GsonConverterFactory;
import retrofit.Response;
import retrofit.Retrofit;

@ContentView(R.layout.activity_test)
public class TestActivity extends AppCompatActivity {
    private static final String TAG = TestActivity.class.getSimpleName();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
    }

    @Event(R.id.button10)
    private void getEvent(View v){
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Constants.LOCAL_HOST)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        LocalService localService = retrofit.create(LocalService.class);
        Call<User> userCall = localService.getUser("get");
        userCall.enqueue(new Callback<User>() {
            @Override
            public void onResponse(Response<User> response, Retrofit retrofit) {
                Log.i(TAG, response.body().toString());
            }

            @Override
            public void onFailure(Throwable t) {
                Log.i(TAG, "onFailure: "+t);
            }
        });
    }
}
